﻿using EasyAdmin.Application.Contracts.Systems.Roles.Dtos;
using EasyAdmin.Application.Contracts.Systems.Roles;
using EasyAdmin.Application.Systems;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using EasyAdmin.Application.Contracts.Systems.Orgs.Dtos;
using Microsoft.AspNetCore.Authorization;

namespace EasyAdmin.Web.Host.Controllers
{
    /// <summary>
    /// 机构管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    //[Authorize]
    public class OrgsController : ControllerBase
    {
        private readonly OrgAppService _orgAppService;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="orgAppService"></param>
        public OrgsController(OrgAppService orgAppService)
        {
            _orgAppService = orgAppService;
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<dynamic> Get([FromQuery] OrgPageCondition condition)
        {
            return await _orgAppService.Page(condition);
        }

        /// <summary>
        /// 创建机构信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task Post([FromBody] CreateUpdateOrgInput input)
        {
            await _orgAppService.CreateOrg(input);
        }

        /// <summary>
        /// 修改机构信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
       public async Task Put([FromBody] CreateUpdateOrgInput input)
        {
            await _orgAppService.UpdateOrg(input);
        }

        /// <summary>
        /// 删除机构信息
        /// </summary>
        /// <param name="orgId"></param>
        /// <returns></returns>
        [HttpDelete("orgId")]
        public async Task Delete([FromRoute] long orgId)
        {
            await _orgAppService.DeleteOrg(orgId);
        }

        /// <summary>
        /// 获得机构详细信息
        /// </summary>
        /// <param name="orgId"></param>
        /// <returns></returns>
        [HttpGet("{orgId}")]
        public async Task<dynamic> Get([FromRoute] long orgId)
        {
            return await _orgAppService.GetOrgByOrgId(orgId);
        }
    }
}
